package com.kystar.muxplayer.model;

import android.os.Parcel;
import android.os.Parcelable;
import java.io.Serializable;


public class Source implements Parcelable,Serializable{

    private int sourceId = 0;
    private SourceType type = SourceType.None;
    private SourceType backup = SourceType.None;//备份源
    private int brightness = 128;//亮度0-255 默认128
    private EDID edid = new EDID();
    private boolean valid = false;

    public int getSourceId() {
        return sourceId;
    }

    public void setSourceId(int sourceId) {
        this.sourceId = sourceId;
    }

    public SourceType getType() {
        return type;
    }

    public void setType(SourceType type) {
        this.type = type;
    }

    public SourceType getBackup() {
        return backup;
    }

    public void setBackup(SourceType backup) {
        this.backup = backup;
    }

    public int getBrightness() {
        return brightness;
    }

    public void setBrightness(int brightness) {
        this.brightness = brightness;
    }

    public EDID getEdid() {
        return edid;
    }

    public void setEdid(EDID edid) {
        this.edid = edid;
    }

    public boolean isValid() {
        return valid;
    }

    public void setValid(boolean valid) {
        this.valid = valid;
    }

    public String getInfo() {
        return edid.getInfo();
    }


    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(this.sourceId);
        dest.writeInt(this.type == null ? -1 : this.type.ordinal());
        dest.writeInt(this.backup == null ? -1 : this.backup.ordinal());
        dest.writeInt(this.brightness);
        dest.writeParcelable(this.edid, flags);
        dest.writeByte(this.valid ? (byte) 1 : (byte) 0);
    }

    public Source() {
    }

    protected Source(Parcel in) {
        this.sourceId = in.readInt();
        int tmpType = in.readInt();
        this.type = tmpType == -1 ? null : SourceType.values()[tmpType];
        int tmpBackup = in.readInt();
        this.backup = tmpBackup == -1 ? null : SourceType.values()[tmpBackup];
        this.brightness = in.readInt();
        this.edid = in.readParcelable(EDID.class.getClassLoader());
        this.valid = in.readByte() != 0;
    }

    public static final Creator<Source> CREATOR = new Creator<Source>() {
        @Override
        public Source createFromParcel(Parcel source) {
            return new Source(source);
        }

        @Override
        public Source[] newArray(int size) {
            return new Source[size];
        }
    };
}
